<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: admuppathadd.php,v $ 
 * $Date: 2005/08/29 13:25:11 $ 
 * $Revision: 1.2 $ 
 * 
 * ********* CVS HEADER ********* 
 */
if($action=="process"){
    if($pathid==-1){
        $query="INSERT INTO rportal_upload_path (id,nom,path,droit,filetype,script,param,droit_download) VALUES ('','$pathnom','$path','$droit','$type','$script','$param','$download')";
        @rportalrequete($query) or die ("ERREUR<br>$query");
    } else {
        $query="UPDATE rportal_upload_path SET nom='$pathnom',path='$path',droit='$droit',filetype='$type',script='$script',param='$param',droit_download='$download' WHERE id='$pathid'";   
        @rportalrequete($query) or die ("ERREUR<br>$query");
    }
    header("Location: ?op=admuppathliste");
    exit;
}
require_once("module/TPLN/TPLN.php"); 
$TPLN = new TPLN; 
$TPLN->Open($op_basepath."tpl/admuppathadd.html"); 
$TPLN->IncludeFile("header","environnement/$session[environnement]/header.php"); 
$TPLN->IncludeFile("footer","environnement/$session[environnement]/footer.php");

require_once(get_path_module("admin"));
$pc = new panneau_controle();
$pc->calculRubriqueParFonction('admuppathliste');
$TPLN->Parse("panneau_controle",$pc->retourneEntete());

$TPLN->Parse("action","?op=admuppathadd");
$droit=2;
$script="";
$download=2;
if($pathid==-1){
/**
  * On ajoute un nouveau path
  */   
    $TPLN->Parse("pathid","-1"); 
    $TPLN->Parse("nom","");
    $TPLN->Parse("path","");
    $TPLN->Parse("type","");
    $TPLN->Parse("param","");
    
}else{
/**
  * On modifie un path
  */   
    $query="SELECT * FROM rportal_upload_path WHERE id='$pathid'";
    $result=rportalrequete($query) or die ("ERREUR<br>$query");
    if($row=rportalligne($result)){
        $TPLN->Parse("pathid",$row['id']); 
        $TPLN->Parse("nom",$row['nom']);
        $TPLN->Parse("path",$row['path']);
        $TPLN->Parse("type",$row['filetype']);
        $TPLN->Parse("param",$row['param']);
        $script=$row['script'];
        $droit=$row['droit'];
        $download=$row['droit_download'];
    } else {
        $TPLN->Parse("pathid","-1"); 
        $TPLN->Parse("nom","");
        $TPLN->Parse("path","");
        $TPLN->Parse("type","");
        $TPLN->Parse("param","");
    }
}
$query="SELECT groupe.* FROM groupe,hierarchie WHERE groupe.id=hierarchie.id_groupe AND hierarchie.id_groupe_dessus='$session[id_groupe]'";
$result=rportalrequete($query) or die ("ERREUR<br>$query");
while($row=rportalligne($result)) {
    $TPLN->Parse("bloc1.groupe",$row['nom']); 
    $TPLN->Parse("bloc1.valeur",$row['id']); 
    $TPLN->Parse("bloc2.groupe",$row['nom']); 
    $TPLN->Parse("bloc2.valeur",$row['id']); 
    if($droit==$row['id']) $TPLN->Parse("bloc1.selected","selected"); 
    else $TPLN->Parse("bloc1.selected",""); 
    if($download==$row['id']) $TPLN->Parse("bloc2.selected","selected"); 
    else $TPLN->Parse("bloc2.selected",""); 
    $TPLN->Loop("bloc1"); 
    $TPLN->Loop("bloc2"); 
} 

function file_name($fichier) 
{ 
return substr($fichier,0,strlen($fichier)-4); 
} 

function file_ext($fichier) 
{ 
return substr(strrchr($fichier, '.'), 1); 
} 

$dir=dir('module/upload/');
$isfile=0;
while ($file = $dir->read()) {
    if(file_ext($file)=='php') {
        if (is_file('module/upload/'.$file)) {
        $isfile=1;
        $TPLN->Parse("script.script",file_name($file));
        if($script==file_name($file))
            $TPLN->Parse("script.selected","selected"); 
        else 
            $TPLN->Parse("script.selected","");
        $TPLN->Loop("script"); 
        }
    }
} 
if($isfile==0) $TPLN->EraseBloc("script");
$TPLN->Write(); 
?>